/**
 * @description 表格列对象
 */

import { onCheckCode } from "@/api/baseData/projectName";

export default function getColumns(id?: any) {
  return [
    {
      title: "项目编码",
      key: "projectCode",
      width: 0,
      align: "center",
      search: {
        show: true,
        title: "项目编码",
      },
      form: {
        show: true,
        order: 1,
        formItem: {
          rules: [
            {
              required: true,
              trigger: "change",
              message: "标准编码为必填项",
            },
            {
              trigger: "blur",
              asyncValidator: (rule, value) => {
                return new Promise((resolve, reject) => {
                  if (value) {
                    let parmas: any = { projectCode: value };
                    if (id) {
                      parmas.id = id;
                    }
                    onCheckCode(parmas)
                      .then(() => {
                        resolve(true);
                      })
                      .catch(() => {
                        reject("项目编码已经存在");
                      });
                  } else {
                    reject("标准编码为必填项");
                  }
                });
              },
            },
          ],
        },
      },
    },
    {
      title: "项目名称",
      key: "projectNameZhCn",
      width: 0,
      align: "center",
      // ellipsis: true,
      // tooltip: true,
      // formatData: false,
      search: {
        show: true,
      },
      form: {
        show: true,
        name: "Input",
        grid: { span: "24" },
        formItem: {
          rules: [
            {
              required: true,
              trigger: "change",
              message: "请输入项目名称",
            },
          ],
        },
      },
    },
    {
      title: "英文名称",
      key: "projectNameEn",
      width: 0,
      align: "center",
      form: {
        show: true,
        name: "Input",
        grid: { span: "24" },
      },
    },
    {
      title: "饱和度(%)",
      key: "saturation",
      width: 0,
      align: "center",
      form: {
        show: true,
        grid: { span: "24" },
        component: {
          name: "Input",
        },
      },
    },
    {
      title: "化学文摘号",
      key: "chemicalAbstracts",
      width: 0,
      align: "center",
      form: {
        show: true,
        name: "Input",
        grid: { span: "24" },
      },
    },
    {
      title: "说明",
      key: "remarks",
      width: 0,
      align: "center",
      show: false,
      search: {
        show: false,
      },
      form: {
        show: true,
        component: { type: "textarea", rows: 2 },
        grid: { span: "24" },
      },
    },
    {
      title: "添加日期",
      key: "createDate",
      width: 150,
      align: "center",
      viewForm: {
        show: false,
      },
    },
    {
      title: "添加人",
      key: "createByName",
      width: 150,
      align: "center",
      viewForm: {
        show: false,
      },
    },
    {
      title: "修改人",
      key: "createByName",
      width: 150,
      align: "center",
      viewForm: {
        show: false,
      },
    },
    {
      title: "修改日期",
      key: "updateDate",
      width: 150,
      align: "center",
      viewForm: {
        show: false,
      },
    },

    {
      title: "操作",
      key: "handle",
      width: 240,
      align: "center",
      slot: "operOptions",
      viewForm: {
        show: false,
      },
    },
  ];
}
